package com.gxc.controller;

import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxc.dto.UploadModelZipResultDto;
import com.gxc.service.UploadService;
import com.gxc.utils.CheckEmptyUtil;
import com.gxc.utils.RestControllerResult;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Resource;
import javax.validation.constraints.Size;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传 Demo Controller.
 *
 * @author 宫新程
 * @since 2019/3/6 13:30
 */
@Slf4j
@RestController
public class UploadController {

  @Resource private UploadService uploadService;

  /** 上传.zip, 不解压读取内容. */
  @PostMapping("/upload-model-zip")
  public RestControllerResult<UploadModelZipResultDto> uploadModelZip(MultipartFile file) {
    // 判断文件是否为空
    if (CheckEmptyUtil.isEmpty(file) || file.getSize() <= 0) {
      return null;
    }
    UploadModelZipResultDto uploadModelZipResultDto = uploadService.uploadModelZip(file);
    return RestControllerResult.success(uploadModelZipResultDto);
  }

}
